package org.lql.algo.codecrush.hot100.doublePointer;

import java.util.Arrays;

/**
 * @author: liangqinglong
 * @date: 2025-09-08 11:19
 * @description: 283. 移动零 <a href="https://leetcode.cn/problems/move-zeroes/description/?envType=study-plan-v2&envId=top-100-liked">...</a>
 **/
public class MoveZeroes {

	public void moveZeroes(int[] nums) {
		int cnt = 0;
		for (int i = 0; i < nums.length; i++) {
			if (nums[i] != 0) {
				nums[cnt++] = nums[i];
			}
		}
		while (cnt < nums.length) {
			nums[cnt++] = 0;
		}
	}

	public static void main(String[] args) {
		MoveZeroes moveZeroes = new MoveZeroes();
		int[] ints = {0, 1, 0, 3, 12};
		moveZeroes.moveZeroes(ints);
		System.out.println(Arrays.toString(ints));
		int[] ints1 = {0};
		moveZeroes.moveZeroes(ints1);
		System.out.println(Arrays.toString(ints1));
		int[] ints2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
		moveZeroes.moveZeroes(ints2);
		System.out.println(Arrays.toString(ints2));
	}
}
